<?php
namespace App\Admin\Controllers;

use App\Models\WxMenu;
use Dcat\Admin\Form;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Tree;
use Dcat\Admin\Http\Controllers\AdminController;

class WxMenuController extends AdminController
{
    public function index(Content $content)
    {
        return $content->header('全局菜单')->description('注意：id(1-30)的菜单都不可以删除，有固定位置的使用或者待定，你应该修改它下面的子级分类')
            ->body(function (Row $row) {
                $tree = new Tree(new WxMenu());
                $tree->expand();
                $tree->maxDepth(3);
//                $tree->disableCreateButton();
                $row->column(12, $tree);
            });
    }

    protected function form()
    {
        return Form::make(new WxMenu(), function (Form $form) {
            $form->display('id');
            $form->select('parent_id', '父级')->options((new WxMenu())->selectOptions());
            $form->text('title', '名称');
            $form->icon('icon', '图标')->default('');
            $form->text('url', '路径')->help('<a href="https://doc.minisns.cn/doc/44/" target="_blank">路径大全</a>');

            $form->deleting(function (Form $form){
                global $__MINI_GLOBAL_TENANT_ID__;
                if($__MINI_GLOBAL_TENANT_ID__ > 0){
                    return $form->response()->error('权限不足，不可以删除其他分站对象');
                }
                if($form->id >= 1 && $form->id <= 30){
                    return $form->response()->error('不能删除1-30的菜单！');
                }
            });

        });
    }

}
